<?
/*

    This file is part of Blue Violin.

    Blue Violin is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Blue Violin is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero Public License for more details.

    You should have received a copy of the GNU Affero Public License
    along with Blue Violin.  If not, see <http://www.gnu.org/licenses/>.

    Blue Violin  Copyright (C) 2008  Blue Violin, Inc. & Josh Watts <josh.watts@blueviolin.org>
	For more information, visit http://www.blueviolin.org/

    This program comes with ABSOLUTELY NO WARRANTY.

*/

session_start();
require_once("./classes/BVScripts.php");
require_once("./classes/Reports.php");
require_once("./classes/Profiles.php");
require_once("../general.php");

$oBVScripts = new BVScripts();
switch ($req_action)
{
	case "getnewlogin":
		$oBVScripts->GetNewLogin();
		break;


	case "createlogin":
		$xmlList = $oBVScripts->CreateLogin($req_email, $req_pwd);
		header("Content-Type: text/xml");
		echo($xmlList);
		break;

	case "list":
/* 		$xmlList = $oBVScripts->GetList(); */
/* 		header("Content-Type: text/xml"); */
/* 		echo($xmlList); */
/* 		break;
 */
		$sJson = $oBVScripts->GetList();
		header("Content-Type: application/json");
		echo($sJson);
		break;
		
	case "load":
		$xmlScript = $oBVScripts->LoadScript($req_name);
		header("Content-Type: text/xml");
		echo($xmlScript);
		break;

	case "checklogin":
		$sResponse = $oBVScripts->CheckLogin();
		echo($sResponse);
		break;

	case "login":
		$xmlList = $oBVScripts->Login($req_email, $req_pwd);
		header("Content-Type: text/xml");
		echo($xmlList);
		break;
		
		
	case "save":
		$oBVScripts->SaveScript($req_name, $req_script);
		break;


	case "savereport":
		$oReports = new BVReports();
		$oReports->SaveReport($req_result, $req_report);
		$oReports->Destruct();
		break;

	case "gethistoricalreportlist":
		$oReports = new BVReports();
		$sJson = $oReports->GetHistoricalReportList();
		header("Content-Type: application/json");
		echo($sJson);
		break;

	case "getreport":
		$oReports = new BVReports();
		$sJson = $oReports->GetReport($req_guid);
		header("Content-Type: application/json");
		echo($sJson);
		break;

	// profiles

	case "createprofile":
		$oProfiles = new BVProfiles();
		$oProfiles->CreateProfile($req_name, $req_defaultUrl, $req_emailOnlyOnFail);
		$oProfiles->Destruct();
		break;

	case "openprofile":
		$oProfiles = new BVProfiles();
		$sJson = $oProfiles->OpenProfile($req_guid);
		echo($sJson);
		break;

	case "editprofile":
		$oProfiles = new BVProfiles();
		$sJson = $oProfiles->EditProfile($req_guid, $req_name, $req_url, $req_emailOnlyOnFail);
		echo($sJson);
		break;

}
$oBVScripts->Destruct();
?>